package elasticsearch

import (
	"car_srv/appconfig"
	"fmt"
	"github.com/elastic/go-elasticsearch/v7"
	"github.com/zeromicro/go-zero/core/logx"
)

var ES *elasticsearch.Client

func Init() {
	var err error
	esCong := appconfig.AppCong.Elasticsearch
	addr := fmt.Sprintf("%s:%d", esCong.Host, esCong.Port)
	cfg := elasticsearch.Config{
		Addresses: []string{
			addr,
		},
	}
	ES, err = elasticsearch.NewClient(cfg)
	if err != nil {
		panic("elasticsearch 连接配置失败")
	}
	logx.Info("elasticsearch 连接配置成功")
}
